/*******************************************************************************
 * Copyright (c) 2009 Kevin Bierhoff and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Kevin Bierhoff - initial API and implementation
 *******************************************************************************/
package com.googlecode.twelfdevtools.model;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.Position;

class FileBasedFileModel extends AbstractElfFileModel {

	FileBasedFileModel(TwelfProjectImpl parent, IFile resource) {
		super(parent, resource);
	}

	@Override
	protected List<TwelfConstantImpl> getAllMarkers(String markerType, boolean includeSubtypes)
			throws CoreException {
		// get all typing markers in the given file
		IMarker[] typeMarkers = file.findMarkers(
				markerType, 
				includeSubtypes,
				IResource.DEPTH_ZERO /* just this file */);
		
		List<TwelfConstantImpl> result = new ArrayList<TwelfConstantImpl>();
		
		for (IMarker m : typeMarkers) {
			int start = m.getAttribute(IMarker.CHAR_START, -1);
			int end = m.getAttribute(IMarker.CHAR_END, -1);
			if (start >= 0 && end >= 0)
				result.add(createConstantModel(m, new Position(start, end - start)));
		}
		
		return result;
	}
}
